-- show_key
-- Created by chengb Mar/23/2016
-- 未翻开的格子上概率显示钥匙

return {
    apply = function(prop, baseValue)
        return tonumber(prop[3]);
    end,

    trigger = function(who, prop, arg)
        local ratio = prop[3];
        local rand = DungeonM.getRandSeed("show_key") % 1000;
        if rand > ratio then
            -- 没有触发显示钥匙怪
            return;
        end

        for pos = 1, GRID_SIZE do
            local grid = DungeonM.getGridByPos(pos);
            if grid:isMonster() and grid.has_key == 1 then
                -- 标记显示钥匙怪
                if grid.monster.dbase:query("show_key") ~= 1 and not grid.monster:isBoss() then
                    grid.monster.dbase:set("show_key", 1);

                    if who.type == OBJECT_TYPE_SUMMON then
                        EventMgr.fire(event.MARK_MONSTER, {["pos"] = grid:getPos(),});
                    end
                end
                break;
            end
        end
    end,

    record = function(target, prop, path)
        local v = target.dbase:queryTemp("prop", path, {});
        table.insert(v, prop);
        target.dbase:setTemp("prop", path, v);

        return true;
    end
};
